using System;
using System.Collections.Generic;
using UnityEngine;

namespace ConsentManagementProviderLib.Android
{
	internal class ConsentWrapperAndroid
	{
		private AndroidJavaObject consentLib;

		private AndroidJavaObject activity;

		private SpClientProxy spClient;

		private AndroidJavaConstruct constructor;

		private CustomConsentClient customConsentClient;

		private static ConsentWrapperAndroid instance;

		public static ConsentWrapperAndroid Instance
		{
			get
			{
				if (instance == null)
				{
					instance = new ConsentWrapperAndroid();
				}
				return instance;
			}
			private set
			{
				instance = value;
			}
		}

		private ConsentWrapperAndroid()
		{
		}

		public void InitializeLib(List<SpCampaign> spCampaigns, int accountId, int propertyId, string propertyName, MESSAGE_LANGUAGE language, CAMPAIGN_ENV campaignsEnvironment, long messageTimeoutMilliSeconds = 3000L)
		{
		}

		public void LoadMessage(string authId = null)
		{
		}

		public void LoadPrivacyManager(CAMPAIGN_TYPE campaignType, string pmId, PRIVACY_MANAGER_TAB tab)
		{
		}

		public void CustomConsentGDPR(string[] vendors, string[] categories, string[] legIntCategories, Action<GdprConsent> onSuccessDelegate)
		{
			customConsentClient = new CustomConsentClient(onSuccessDelegate);
			consentLib.Call("customConsentGDPR", vendors, categories, legIntCategories, customConsentClient);
		}

		public GdprConsent GetCustomGdprConsent()
		{
			if (customConsentClient != null)
			{
				return customConsentClient.customGdprConsent;
			}
			return null;
		}

		internal void Dispose()
		{
			if (consentLib != null)
			{
				constructor.Dispose();
				CmpDebugUtil.Log("Disposing consentLib...");
				consentLib.Call("dispose");
				CmpDebugUtil.Log("Disposing consentLib successfully done");
			}
		}

		internal void CallShowView(AndroidJavaObject view)
		{
			consentLib.Call("showView", view);
			CmpDebugUtil.Log("C# : View showing passed to Android's consent lib");
		}

		internal void CallRemoveView(AndroidJavaObject view)
		{
			consentLib.Call("removeView", view);
			CmpDebugUtil.Log("C# : View removal passed to Android's consent lib");
		}

		private void RunOnUiThread(Action action)
		{
			CmpDebugUtil.Log(">>>STARTING RUNNABLE ON UI THREAD!");
			activity.Call("runOnUiThread", new AndroidJavaRunnable(action.Invoke));
		}

		private void InvokeLoadMessage()
		{
			CmpDebugUtil.Log("InvokeLoadMessage() STARTING...");
			try
			{
				consentLib.Call("loadMessage");
				CmpDebugUtil.Log("loadMessage() is OK...");
			}
			catch (Exception ex)
			{
				CmpDebugUtil.LogError(ex.Message);
			}
			finally
			{
				CmpDebugUtil.Log("InvokeLoadMessage() DONE");
			}
		}

		private void InvokeLoadPrivacyManager(string pmId, AndroidJavaObject tab, AndroidJavaObject campaignType, CAMPAIGN_TYPE campaignTypeForLog)
		{
			CmpDebugUtil.Log("InvokeLoadPrivacyManager() STARTING...");
			try
			{
				consentLib.Call("loadPrivacyManager", pmId, tab, campaignType);
				CmpDebugUtil.Log($"loadPrivacyManager() with {campaignTypeForLog} is OK...");
			}
			catch (Exception ex)
			{
				CmpDebugUtil.LogError(ex.Message);
			}
			finally
			{
				CmpDebugUtil.Log($"InvokeLoadPrivacyManager() with {campaignTypeForLog} DONE");
			}
		}

		private void InvokeLoadMessageWithAuthID(string authID)
		{
			CmpDebugUtil.Log("loadMessage(authId: String) STARTING...");
			try
			{
				consentLib.Call("loadMessage", authID);
			}
			catch (Exception ex)
			{
				CmpDebugUtil.LogError(ex.Message);
			}
			finally
			{
				CmpDebugUtil.Log("loadMessage(authId: String) DONE");
			}
		}

		public SpConsents GetSpConsents()
		{
			if (spClient != null)
			{
				return spClient._spConsents;
			}
			return null;
		}
	}
}
